package com.moka.db;

import android.content.Context;
import android.database.sqlite.SQLiteOpenHelper;

import com.moka.db.dao.BaseDao;

public class DatabaseFactory {
	
	private DatabaseFactory(){}
	
	public static BaseDao getDatabaseHelper(Context context,String dbName){
		
		SQLiteOpenHelper helper = null;
		
		if(helper == null){
			
			DatabaseVersionManager dvm = new DatabaseVersionManager(context);
			
			int newVersion = Configuration.getNewVersion(dbName);
			
			int oldVersion = dvm.getVersion(dbName);
			
			if(newVersion - oldVersion > 0){
				
				helper = DatabaseHelper.getDatabaseHelper(context,dbName, newVersion, oldVersion);
				
			}else{
				
				helper = DatabaseHelper.getDatabaseHelper(context,dbName, newVersion, newVersion);
			}
			
		}
		
		return new BaseDao(helper);
		
	}
	
}
